#include "StdAfx.h"
#include "AppIniConfigAdapter.h"
#include "Util.h"

CAppIniConfigAdapter::CAppIniConfigAdapter(void)
{
}

CAppIniConfigAdapter::~CAppIniConfigAdapter(void)
{
}

BOOL CAppIniConfigAdapter::Init(LPCTSTR strFileName)
{
    mIniFileName = strFileName;
    return true;
    //return CUtil::IsExitFile(strFileName);
}

BOOL CAppIniConfigAdapter::WriteString(LPCTSTR lpSectionName, LPCTSTR lpKeyName, LPCTSTR lpStringNmae)
{
    return ::WritePrivateProfileString(lpSectionName,lpKeyName,lpStringNmae,mIniFileName);
}

BOOL CAppIniConfigAdapter::WriteInteger(LPCTSTR lpSectionName, LPCTSTR lpKeyName, int nIntValue)
{
	CString lpStringNmae;
	lpStringNmae.Format(_T("%d"),nIntValue);
	return ::WritePrivateProfileString(lpSectionName,lpKeyName,lpStringNmae,mIniFileName);
}

CString CAppIniConfigAdapter::GetString(LPCTSTR lpSectionName, LPCTSTR lpKeyName)
{
	TCHAR tRetStr[1024];
	::GetPrivateProfileString(lpSectionName,lpKeyName,_T(""),tRetStr,1024,mIniFileName);
	CString str;
	str.Format(_T("%s"),tRetStr);
	return str;
}

int CAppIniConfigAdapter::GetInteger(LPCTSTR lpSectionName, LPCTSTR lpKeyName)
{
	return ::GetPrivateProfileInt(lpSectionName,lpKeyName,0,mIniFileName);
}

CString CAppIniConfigAdapter::GetInjectDllName(void)
{
	return GetString(NULL,_T("DLL"));
}

BOOL CAppIniConfigAdapter::WriteUsername(CString str)
{
	return WriteString(_T("General"),_T("Username"),str);
}

CString CAppIniConfigAdapter::GetUsername(void)
{
	return GetString(_T("General"),_T("Username"));
}

BOOL CAppIniConfigAdapter::WritePassword(CString str)
{
	return WriteString(_T("General"),_T("Password"),str);
}

CString CAppIniConfigAdapter::GetPassword(void)
{
	return GetString(_T("General"),_T("Password"));
}

BOOL CAppIniConfigAdapter::WriteUsernameWOW(CString str)
{
	return WriteString(_T("General"),_T("UsernameWOW"),str);
}

CString CAppIniConfigAdapter::GetUsernameWOW(void)
{
	return GetString(_T("General"),_T("UsernameWOW"));
}

BOOL CAppIniConfigAdapter::WritePasswordWOW(CString str)
{
	return WriteString(_T("General"),_T("PasswordWOW"),str);
}

CString CAppIniConfigAdapter::GetPasswordWOW(void)
{
	return GetString(_T("General"),_T("PasswordWOW"));
}


BOOL CAppIniConfigAdapter::WriteExePath(CString str)
{
	return WriteString(_T("General"),_T("ExePath"),str);
}

CString CAppIniConfigAdapter::GetExePath(void)
{
	return GetString(_T("General"),_T("ExePath"));
}

BOOL CAppIniConfigAdapter::WriteWowServerType(CString str)
{
	return WriteString(_T("General"),_T("WowServerType"),str);
}

CString CAppIniConfigAdapter::GetWowServerType(void)
{
	return GetString(_T("General"),_T("WowServerType"));
}

BOOL CAppIniConfigAdapter::WriteWowVersionType(CString str)
{
	return WriteString(_T("General"),_T("WowVersionType"),str);
}

CString CAppIniConfigAdapter::GetWowVersionType(void)
{
	return GetString(_T("General"),_T("WowVersionType"));
}

BOOL CAppIniConfigAdapter::WriteVersion(CString str)
{
	return WriteString(_T("Version"),_T("version"),str);
}

CString CAppIniConfigAdapter::GetVersion(void)
{
	return GetString(_T("Version"),_T("version"));
}

BOOL CAppIniConfigAdapter::SetSaveUsername(BOOL b)
{
	if(b)
	{
		return WriteString(_T("General"),_T("SaveUsername"),_T("1"));
	}
	else
	{
		return WriteString(_T("General"),_T("SaveUsername"),_T("0"));
	}
}

BOOL CAppIniConfigAdapter::GetSaveUsername(void)
{
	if(GetInteger(_T("General"), _T("SaveUsername")) == 1)
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

BOOL CAppIniConfigAdapter::SetSavePWD(BOOL b)
{
	if(b)
	{
		return WriteString(_T("General"),_T("SavePWD"),_T("1"));
	}
	else
	{
		return WriteString(_T("General"),_T("SavePWD"),_T("0"));
	}
}

BOOL CAppIniConfigAdapter::GetSavePWD(void)
{
	if(GetInteger(_T("General"), _T("SavePWD")) == 1)
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

BOOL CAppIniConfigAdapter::SetSaveUsernameWOW(BOOL b)
{
	if(b)
	{
		return WriteString(_T("General"),_T("SaveUsernameWOW"),_T("1"));
	}
	else
	{
		return WriteString(_T("General"),_T("SaveUsernameWOW"),_T("0"));
	}
}

BOOL CAppIniConfigAdapter::GetSaveUsernameWOW(void)
{
	if(GetInteger(_T("General"), _T("SaveUsernameWOW")) == 1)
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

BOOL CAppIniConfigAdapter::SetSavePWDWOW(BOOL b)
{
	if(b)
	{
		return WriteString(_T("General"),_T("SavePWDWOW"),_T("1"));
	}
	else
	{
		return WriteString(_T("General"),_T("SavePWDWOW"),_T("0"));
	}
}

BOOL CAppIniConfigAdapter::GetSavePWDWOW(void)
{
	if(GetInteger(_T("General"), _T("SavePWDWOW")) == 1)
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}